package com.ml.mall.api.notifation;

import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.notifation.NotifationEditDto;
import com.ml.mall.bean.req.notifation.NotifationNewDto;
import com.ml.mall.bean.req.notifation.NotifationQueryDto;
import com.ml.mall.bean.req.notifation.NotifationQueryOneDto;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.enums.RetStatusNum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.Valid;
import java.util.List;
import com.ml.mall.annotations.OperLog;
import com.ml.mall.service.notifation.SysANotifationService;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "【auth】通知相关接口")
@RequestMapping("/notification")
@RestController
public class SysANotifationController extends BaseController{

     @Autowired
     private SysANotifationService sysANotifationService;


    @RequestMapping(method = RequestMethod.POST, path = "/query_page")
    @ApiOperation("通知分页查询")
//  @RequiresPermissions(PermissionConst.NOTIFICATION_QUERY_PAGE)
    public ApiRestResult sysANotifationQueryPage(@RequestBody NotifationQueryDto dto) {
        return ApiRestResult.ok(sysANotifationService.queryPageNotifation(dto));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/query_one")
    @ApiOperation("通知查询单个")
//  @RequiresPermissions(PermissionConst.NOTIFICATION_QUERY_ONE)
    public ApiRestResult sysANotifationQueryOne(@Valid @RequestBody NotifationQueryOneDto dto) {
        return ApiRestResult.ok(sysANotifationService.queryOneNotifation(dto));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @ApiOperation("通知新增")
//  @RequiresPermissions(PermissionConst.NOTIFICATION_NEW)//未发现调用
    public ApiRestResult sysANotifationNew(@Valid @RequestBody NotifationNewDto dto ) {
        sysANotifationService.createNotifation(dto);
        return ApiRestResult.ok();
    }


    @RequestMapping(method = RequestMethod.POST, path = "/edit")
    @ApiOperation("通知修改")
//  @RequiresPermissions(PermissionConst.NOTIFICATION_EDIT)
    public ApiRestResult sysANotifationEdit(@Valid @RequestBody NotifationEditDto dto ) {
        sysANotifationService.editNotifation(dto);
        return ApiRestResult.ok();
    }


    @RequestMapping(method = RequestMethod.POST, path = "/del")
    @ApiOperation("通知删除")
//  @RequiresPermissions(PermissionConst.NOTIFICATION_DEL)
    public ApiRestResult sysANotifationDel(@RequestBody List<Long> ids) {
        if(ids==null||ids.size()<1){
            return ApiRestResult.err(RetStatusNum.PARAMS_ERROR.getMessage(), RetStatusNum.PARAMS_ERROR.getCode());
        }
        sysANotifationService.delNotifation(ids);
        return ApiRestResult.ok();
    }
}
